package java学习.第18章_JDK8_17新特性;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.List;
import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class User {
    private Integer id;
    private String username;
    private int age;
    private List<String> list;


    public User(Integer id, String username, int age) {
        this.id = id;
        this.username = username;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {

//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        User user = (User) o;
//        return age == user.age && Objects.equals(id, user.id) && Objects.equals(username, user.username);

        //JDK 14-16 的 instanceof 新特性      o instanceof User user
        return o instanceof User user &&
                user.id.equals(this.id) &&
                user.username.equals(this.username) &&
                user.age == this.age;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, username, age);
    }
}
